package com.atguigu.IO;

import java.io.*;
import java.util.Scanner;

public class demo4 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入源文件:");
        File src=new File(scanner.next());
        System.out.println("请输入目标文件:");
        File dest=new File(scanner.next());
        if(!src.isFile()){
            System.out.println("输入的源文件有问题");
            return;
        }
        if(!dest.getParentFile().isDirectory()){
            System.out.println("输入的目标文件有问题");
            return;
        }
        //2.拷贝操作
        try{
            InputStream inputStream=new FileInputStream(src);
            OutputStream outputStream=new FileOutputStream(dest);
            //读src的每个字节写入到dest中
            while(true){
                int ret=inputStream.read();
                if(ret==-1){
                    break;
                }
                outputStream.write(ret);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
